package com.zxy.supplier_system.server.xinyuan.controller

import com.zxy.supplier_system.server.xinyuan.service.XinyuanGoodsCategoryService
import com.zxy.supplier_system.server.xinyuan.service.toResponse
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/xinyuan/goodsCategories")
class XinyuanGoodsCategoryController(
    private val categoryService: XinyuanGoodsCategoryService
) {

    // 创建分类
    @PostMapping
    fun createCategory(
        @RequestBody request: XinyuanGoodsCategoryService.CreateCategoryRequest
    ): XinyuanGoodsCategoryService.CategoryResponse {
        return categoryService.createCategory(request).toResponse()
    }


    // 更新分类
    @PutMapping("/{id}")
    fun updateCategory(
        @PathVariable id: Int,
        @RequestBody request: XinyuanGoodsCategoryService.UpdateCategoryRequest
    ): XinyuanGoodsCategoryService.CategoryResponse {
        return categoryService.updateCategory(id, request)
    }

    // 删除分类
    @DeleteMapping("/{id}")
    fun deleteCategory(@PathVariable id: Int) {
        categoryService.deleteCategory(id)
    }

    // 获取所有分类（分页）
    @GetMapping
    fun getAllCategories(
        pageable: Pageable
    ): Page<XinyuanGoodsCategoryService.CategoryResponse> {
        return categoryService.getAllCategories(pageable)
    }

    // 获取所有家电分类
    @GetMapping("/homeAppliance")
    fun getAllHomeApplianceCategories(): List<XinyuanGoodsCategoryService.CategoryResponse> {
        return categoryService.getAllHomeApplianceCategories()
    }

    // 获取所有数码分类
    @GetMapping("/digital")
    fun getAllDigitalCategories(): List<XinyuanGoodsCategoryService.CategoryResponse> {
        return categoryService.getAllDigitalCategories()
    }


}